import * as service from '../services';

export default {
  namespace: 'network',
  state: {
    data: {},
    timeoutId: null,
  },
  reducers: {
    save(state, { payload: { data }}) {
      return { ...state, data };
    },
    setTimeoutId(state, { payload: { timeoutId } }) {
      if (!timeoutId) {
        clearTimeout(state.timeoutId);
      }
      return { ...state, timeoutId };
    },
  },
  effects: {
    *fetch({ payload: {}}, {call, put}) {
      const result = yield call(service.getNetworkInfo);
      yield put({
        type: 'save',
        payload: {
          data: result.data,
        }
      })
    }
  },
};


